package org.graduation.model.vo;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.graduation.model.common.note.Note;
import org.graduation.model.common.project.Task;

import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CalendarVO implements VO {
    // 事件id，可以是任务id，可以是备忘录id，取决于Type
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;
    private String type;
    private String title;
    private Date start;

    public static CalendarVO task2CalendarVO(Task task) {
        CalendarVO calendarVO = new CalendarVO();
        calendarVO.setId(task.getTaskId());
        calendarVO.setTitle(task.getName());
        calendarVO.setStart(task.getBeginTime());
        calendarVO.setType(CalendarVOType.TASK.getValue());
        return calendarVO;
    }
    public static CalendarVO note2CalendarVO(Note note) {
        CalendarVO calendarVO = new CalendarVO();
        calendarVO.setId(note.getNoteId());
        calendarVO.setTitle("备忘录");
        calendarVO.setStart(note.getAlarmTime());
        calendarVO.setType(CalendarVOType.NOTE.getValue());
        return calendarVO;
    }
}

enum CalendarVOType {
    TASK("TASK"),
    NOTE("NOTE");
    private String value;

    private CalendarVOType(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    @Override
    public String toString() {
        return getValue();
    }

    public static CalendarVOType of(String value) {
        for (CalendarVOType calendarVOType : CalendarVOType.values()) {
            if (calendarVOType.getValue().equals(value)) {
                return calendarVOType;
            }
        }
        return null;
    }
}